'''
while循环
'''
# num = 0
# while num < 5:
#     num += 1
#     print(num)
import random

# nums = [1, 3, 6, 9]
# for index, num in enumerate(nums):
#     print('下标：', index, '值：', num)

# 1. 什么时候用for循环
# a.循环次数确定
# b.遍历序列

# 2.什么时候用while循环
# a.死循环
# b.循环次数不确定

# 练习：猜数字
# r = random.randint(1, 100)
# while 1:
#     x = int(input('请输入数字：'))
#     if x == r:
#         print('猜中啦！可以去抽奖啦！本轮随机数为：', r)
#         break
#     elif x < r:
#         print('猜小了')
#     else:
#         print('猜大了')

# 4.continue是循环体中的关键字，结束本次循环，继续下次循环
# 5.break是循环体中的关键字，结束整个循环
# for x in range(4):
#     print('===')
#     break

# 6.else
for x in range(4):
    print(x)
    break
else:
    print('else')
print('--->')

# 练习
sum1 = 0
for i in range(1, 11):
    sum2 = 1
    for j in range(1, i + 1):
        sum2 *= j
    sum1 += sum2
print(sum1)

sum3 = 0
sum4 = 1
for num in range(1,11):
    sum4 *= num
    sum3 += sum4
print(sum3)
